package com.example.xiaodu.yuejian12.Activity;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.xiaodu.yuejian12.Bean.LoginBean;
import com.example.xiaodu.yuejian12.Listener.RetrofitListener;
import com.example.xiaodu.yuejian12.Model.UserModel;
import com.example.xiaodu.yuejian12.R;

public class Signup1Activity extends AppCompatActivity {
    private TextView confirm;
    private EditText phone;
    private UserModel userModel;
    private RetrofitListener<LoginBean> listener;
    private SharedPreferences sp;
    private int gid,uid;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_signup1);
        sp=getSharedPreferences("me", MODE_PRIVATE);
        gid=getIntent().getIntExtra("gameID",1);
        uid=sp.getInt("userid",111);

        initView();
        initListener();
        initClick();
    }

    public void initView(){
        confirm=(TextView)findViewById(R.id.confirm);
        phone=(EditText)findViewById(R.id.phone);
    }

    public void initListener(){
        listener=new RetrofitListener<LoginBean>() {
            @Override
            public void onSuccess(LoginBean loginBean) {
                if("1".equals(loginBean.getFlag())){
                    Toast.makeText(Signup1Activity.this,"报名成功",Toast.LENGTH_LONG).show();
                    Signup1Activity.this.finish();
                }
            }

            @Override
            public void onFail(String msg) {

            }
        };
    }

    public void initClick(){
        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                userModel=new UserModel();
                userModel.signupGame(gid,uid,phone.getText().toString(),listener);
            }
        });
    }


}

